import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/Login.vue'),
        meta: { title: '登录' }
    },
    {
        path: '/forget-pass',
        component: () => import('../views/forget-pass'),
        meta: {title: '忘记密码', isToken: false}
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        children: [
            {
                path: '/home',
                redirect: '/index'
            },
            {
                path: '/index',
                name: 'index',
                component: () => import('../views/index/Index.vue'),
                meta: { title: '首页' }
            },
            {
                path: '/class',
                name: 'class',
                component: () => import('../views/class/Class.vue'),
                meta: { title: '课程' }
            },
            {
                path: '/news',
                name: 'news',
                component: () => import('../views/news/News.vue'),
                meta: { title: '资讯' }
            },
            {
                path: '/my',
                name: 'my',
                component: () => import('../views/my/My.vue'),
                meta: { title: '个人中心' }
            },
            {
                path: '/yueke',
                name: 'yueke',
                component: () => import('../views/yueke/Yueke.vue'),
                meta: { title: '图书' }
            },
        ]
    },
    {//用户资料页面
        path: '/info',
        name: 'info',
        component: () => import('../views/my/info'),
        meta: { title: '个人信息' }
    },
    {//用户资料页面
        path: '/sign',
        name: 'sign',
        component: () => import('../views/my/sign'),
        meta: { title: '签到' ,isToken: true}
    },
    {//修改昵称
        path: '/set-info-user',
        name: 'set-info-user',
        component: () => import('../views/my/userInfo/set-info-user'),
        meta: { title: '修改昵称',isToken: true }
    },
    {//修改昵称
        path: '/set-info-sex',
        name: 'set-info-sex',
        component: () => import('../views/my/userInfo/set-info-sex'),
        meta: { title: '修改性别',isToken: true }
    },
    {//设置
        path: '/options',
        name: 'options',
        component: () => import('../views/my/options'),
        meta: { title: '设置', isToken: true }
    },

    {//my 我的学习页面
        path: '/my-study',
        name: 'my-study',
        component: () => import('../views/my/my-son/My-study'),
        meta: { title: '我的学习', isToken: true }
    },
    {//my 学习课时
        path: '/Study-calendar',
        name: 'Study-calendar',
        component: () => import('../views/my/my-son/Study-calendar'),
        meta: { title: '学习课时', isToken: true }
    },
    {//my 我的积分
        path: '/Integral',
        name: 'Integral',
        component: () => import('../views/my/my-son/Integral'),
        meta: { title: '我的积分', isToken: true }
    },
    {//my 我的作业
        path: '/Homework',
        name: 'Homework',
        component: () => import('../views/my/my-son/Homework'),
        meta: { title: '我的作业', isToken: true }
    },
    {//my 我的社区
        path: '/My-community',
        name: 'My-community',
        component: () => import('../views/my/my-son/My-community'),
        meta: { title: '我的社区', isToken: true }
    },
    {//my 课程订单||图书订单
        path: '/order',
        name: 'order',
        component: () => import('../views/my/my-son/Order'),
        meta: { title: '课程订单', isToken: true }
    },
    {//my 优惠券
        path: '/coupon',
        name: 'coupon',
        component: () => import('../views/my/my-son/Coupon'),
        meta: { title: '优惠券', isToken: true }
    },
    {//my 学习卡
        path: '/card',
        name: 'card',
        component: () => import('../views/my/my-son/Card'),
        meta: { title: '学习卡', isToken: true }
    },
    {//my 分销中心
        path: '/distribute',
        name: 'distribute',
        component: () => import('../views/my/my-son/Distribute'),
        meta: { title: '分销中心', isToken: true }
    },
    {//my 消息中心
        path: '/message',
        name: 'message',
        component: () => import('../views/my/my-son/Message'),
        meta: { title: '消息中心', isToken: true }
    },
    {//my 地址管理
        path: '/address',
        name: 'address',
        component: () => import('../views/my/my-son/Address'),
        meta: { title: '地址管理', isToken: true }
    },
    {//my 关于我们
        path: '/about',
        name: 'about',
        component: () => import('../views/my/my-son/About'),
        meta: { title: '关于我们', isToken: true }
    },
    {//my 意见反馈
        path: '/feedback',
        name: 'feedback',
        component: () => import('../views/my/my-son/Feedback'),
        meta: { title: '意见反馈', isToken: true }
    },
    {
        path: '/set-new-pass',
        component: () => import('../views/my/set-new-pass'),
        meta: { title: '设置密码', isToken: true }
    },
    {//搜索
        path: '/search',
        name: 'search',
        component: () => import('../views/index/Search.vue'),
        meta: { title: '搜索' }
    },
    {//大卫天龙页面的课程
        path: '/Course',
        name: 'Course',
        component: () => import('../views/index/Course.vue')
    },
    {
        path: '/registration',
        name: 'registration',
        component: () => import('../views/my/Registration.vue')
    },
    {
        path: '/privacy',
        name: 'privacy',
        component: () => import('../views/my/Privacy.vue')
    },
    {

        path: '/classDetail', //讲师详情页
        name: 'ClassDetail',
        component: () => import('../views/class/ClassDetail.vue')
    },
    {

        path: '/classList', //讲师列表页
        name: 'ClassList',
        component: () => import('../views/class/ClassList.vue')
    },
    {
        path: '/classDizhi', //讲师地址页
        name: 'ClassDizhi',
        component: () => import('../views/class/ClassDizhi.vue'),
        meta: { title: '地址', isToken: true }
    },
    {
        path: '/classAdddizhi', //讲师添加地址页
        name: 'ClassAdddizhi',
        component: () => import('../views/class/ClassAdddizhi.vue')
    },
    {
        path: '/classjiadizhi', //讲师添加/编辑收货地址页
        name: 'Classjiadizhi',
        component: () => import('../views/class/Classjiadizhi.vue')
    },
    {
        path: '/NewDetail', //资讯详情页
        name: 'NewDetail',
        component: () => import('../views/news/NewDetail.vue')
    },
    {
        path: '/yuekexp', //约课详情页
        name: 'yuekexp',
        component: () => import('../views/yueke/Yuekexp.vue')
    }, {
        path: '/Yuekegwc', //约课购物车
        name: 'Yuekegwc',
        component: () => import('../views/yueke/Yuekegwc.vue'),
        meta: { title: '立即购买', isToken: true }
    },
    {
        path: '/Yuekedizhi', //约课地址
        name: 'Yuekedizhi',
        component: () => import('../views/yueke/Yuekedizhi.vue')
    },
    {
        path: '/Yueketj', //约课添加地址
        name: 'Yueketj',
        component: () => import('../views/yueke/Yueketj.vue')
    },
{
  path: '/classtijiao', //讲师提交订单页
  name: 'Classtijiao',
  component: () => import( '../views/class/Classtijiao.vue')
},
    {
        path: '/messageDetail', //从课程通知跳转到详情页
        name: 'messageDetail',
        component: () => import('../views/index/messageDetail.vue')
    },
]


const router = new VueRouter({
    routes

})
router.beforeEach((to, from, next) => {
    // console.log(to)
    let token = localStorage.getItem("adminToken")
    if (token && token != 'null') {
        next()
    } else {
        if (to.meta.isToken) {
            next('/login')
        } else {
            next()
        }
    }
})
router.afterEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    // console.log(to)
    // if(to.meta.title)
    document.title = to.meta.title
})


export default router
